package com.ruoyi.app.controller.project;

import com.ruoyi.app.business.project.ProjectInvoiceBusiness;
import com.ruoyi.app.config.annotation.OperationAuth;
import com.ruoyi.app.domain.project.invoice.InvoiceInfo;
import com.ruoyi.app.domain.project.invoice.InvoiceSave;
import com.ruoyi.common.core.utils.CommonUtils;
import com.ruoyi.common.core.web.domain.APIResult;
import com.ruoyi.common.core.web.page.CommonPageInfo;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.service.project.query.InvoiceQuery;
import com.ruoyi.service.user.enums.UserTypeEnum;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 项目发票管理
 *
 * @author Zane
 * @since 2025-10-10
 */
@OperationAuth({UserTypeEnum.PLATFORM_USER})
@RestController
@RequestMapping("/project/invoice/")
public class ProjectInvoiceController {

  @Resource
  private ProjectInvoiceBusiness projectInvoiceBusiness;

  /**
   * 需要来票项目列表
   */
  @PostMapping("/list")
  public TableDataInfo<InvoiceInfo> listForInvoice(@Validated @RequestBody InvoiceQuery query) {
    CommonPageInfo<InvoiceInfo> projects = projectInvoiceBusiness.listForInvoice(query);
    return CommonUtils.buildTableData(projects);
  }

  /**
   * 项目开票
   */
  @PostMapping("invoice")
  public APIResult<Void> makeInvoice(@Validated @RequestBody InvoiceSave invoiceSave) {
    projectInvoiceBusiness.makeInvoice(invoiceSave);
    return APIResult.success();
  }
}
